package com.changgou.search.controller;


import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.search.service.ESManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/esmanage")
public class ESManagerController {

	@Autowired
	ESManagerService esManagerService;

	/**
	 * 创建索引库结构
	 */
	@GetMapping("/createMappingAndIndex")
	public Result createMappingAndIndex(){
		esManagerService.createMappingAndIndex();
		return new Result(true, StatusCode.OK,"创建索引成功");
	}

	/**
	 * 导入全部数据到ES索引库
	 */
	@GetMapping("/importAll")
	public Result importAll(){
		esManagerService.importAll();
		return new Result(true,StatusCode.OK,"导入全部数据到索引成功");
	}

	/**
	 * 根据spuid导入数据到ES索引库
	 * @param spuId 商品id
	 */
	@GetMapping("/importDataBySpuId/{spuId}")
	public Result importDataBySpuId(@PathVariable("spuId") String spuId){
		esManagerService.importDataBySpuId(spuId);
		return new Result(true,StatusCode.OK,"导入指定数据到索引成功");
	}
}
